<?php
//$loader->requireOnce('includes/Datasource_sql.class.php');

class PrescriptionNote extends ORDataObject {
	var $prescription_note_id	=	'';
	var $vi_note		=	'';
	var $en_note		=	'';
	var $disable	=	'';
	
	var $_table = 'prescription_note';
	var $_key = 'prescription_note_id';
	var $_internalName = 'PrescriptionNote';
	
	function PrescriptionNote(){
		parent::ORDataObject();
	}
	
	public function listAllNotes(){
		$field	=	L10nHelper::getLocale();
		$field	=	L10nHelper::changeField($field,"note");
		$ds		=	new Datasource_sql();
		$sql	=	array(
			'cols'	=>	"prescription_note_id p_note_id, $field note, disable",
			'from'	=>	$this->_table,
			'orderby'=>	"note"
		);
					
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function listAvailableNotes(){
		$field	=	L10nHelper::getLocale();
		$field	=	L10nHelper::changeField($field,"note");
		$ds		=	new Datasource_sql();
		$sql	=	array(
			'cols'	=>	"$field note",
			'from'	=>	"$this->_table",
			'where'	=>	"disable=0"
		);
					
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function disableNote($pnoteId){
		$this->setup($pnoteId);
		$this->set('disable',1);
		$this->persist();
	}
	
	public function enableNote($pnoteId){
		$this->setup($pnoteId);
		$this->set('disable',0);
		$this->persist();
	}
	
	public function addEditPrescriptionNote($noteId, $note){
		$field		=	L10nHelper::getLocale();

       	$data = array();
		if (isset($noteId) && $noteId != '') {
			//edit
			$field		=	L10nHelper::changeField($field, "note");
			$data = array($field => Utils::sanitizeText($note));
            $this->setup($noteId);
       	} else {
       		//add new
       		$locales = L10nHelper::getSupportedLocales();
       		foreach ( $locales as $lo => $la ) {
       			$lo		   =	L10nHelper::changeField($lo, "note");
       			$data[$lo] =	Utils::sanitizeText($note);
       		}      		
       	}
		$this->populateArray($data);
    	$this->persist();
		
		return $this->get('prescription_note_id');
	}

}

?>